< previous page page_218 next page >

Page 218
Figure 7.19 shows a rotated rectangle. If the rectangle's original width and height are W and H, then the figure shows that the rotated area's width and height are given by:
e10a6a0a59f035e870d90cca05b85fce.gif
width  = H * Sin(f) + W * Cos(f)
height = H * Cos(
f) + W * Sin(f)
Example program Rotate is similar to program Trans except it does not use the transformation framework. Its RotateImage subroutine contains the inverse pixel mapping code, so it provides slightly better performance.
Reflection
Reflecting an image across the X or Y axis is easy. To reflect an area with bounds x1 <= x <= x2, y1 <= y <= y2 across the X axis, you could use code like this:
e10a6a0a59f035e870d90cca05b85fce.gif
For Y = y1 To y2 
    For X = x1 To x2 
        to_pixels(X, -Y) = from_pixels(X, Y) 
    Next X 
Next Y
Of course, the array bounds of the to_bytes and from_bytes arrays are probably positive. In that case, the -Y coordinate value used in the to_bytes entries is outside the array bounds. Your code can check for this condition and ignore any values that do not fit within the output array. In this example, every output pixel lies outside the destination array, so this kind of reflection is not particularly useful.
Reflecting an image across a line other than the X or Y axis is more interesting. You can easily do this by translating the image so that the line of reflection falls along one of the
z0238-01.gif
Figure 7.19
Computing the dimensions of a rotated rectangle.

 
< previous page page_218 next page >